--
-- Author: yawei.zhu
-- Date: 2018-08-03 14:39:06
--
local GameDB = import(".GameDB")

function GameDB:getHeroRoads()
	return self:getCachedValues("herosroad", nil, function(a, b)
		if tonumber(a.layer) ~= tonumber(b.layer) then
			return tonumber(a.layer) < tonumber(b.layer)
		else
			return tonumber(a.order) < tonumber(b.order)
		end
    end)
end

-- 获取英雄之路的层级数
function GameDB:getHeroRoadLength()
	local configs = self:getCachedValues("herosroad", nil, function(a, b)
        return tonumber(a.layer) < tonumber(b.layer)
    end)

    return configs[#configs].layer
end

-- 英雄之路 根据layer 和 order 获取当前节点信息
-- classID 不为空的时候就把 职业对应的信息添加进来
function GameDB:getHeroInfoByIndex(layer, order, classID)
	local configs = self:getCachedValues("herosroad")

	local info = nil
	for _, data in ipairs(configs) do
		if tonumber(data.layer) == layer and tonumber(data.order) == order then
			info = data
		end
	end

	if info and classID and classID > 0 then
		local formationID = info["class"..classID]
		if formationID then
			local formation = self:queryHeroFormationByID(formationID)
			info.classId = formationID
			info.icon = formation.icon
			info.bnpcName = formation.bnpcName
			info.powerNeed = formation.powerNeed
			info.battleID = formation.battleID
			info.help = formation.help
			info.teachID = formation.teachID
			info.spec_typeID = formation.spec_typeID
		end 
	end

	return info
end


function GameDB:queryHeroFormationByID(formationID)
	return self:getCachedValue("herosroad_formation", formationID)
end

function GameDB:queryBoxInfoByLevel(level)
	return self:getCachedValue("herosroad_box", level)
end

function GameDB:getTeachSkillIds(id)
	local list = self:getCachedValues("herosroad_teach", function(v)
		return tonumber(v.belong) == id 
	end)
	local skillIds = {}
	for _, data in ipairs(list) do
		if tonumber(data.skillType) == 1 then
			table.insert(skillIds, tonumber(data.team))
		end
	end
	return skillIds
end

function GameDB:getHeroRoadMapBorder(mapId)
	return self:getCachedValue("herosroad_map", mapId)
end

return GameDB
